using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using WLYT.Admin.WebApi.Models;
using WLYT.Application.Interfaces;
using WLYT.Domain.Model;

namespace WLYT.Admin.WebApi.Controllers
{
    public class RoleController : BaseController
    {
        private readonly IRoleService RoleService;

        public RoleController(IRoleService roleService)
        {
            RoleService = roleService;
        }

        [HttpGet]
        [Route("api/Role/GetData")]
        public async Task<Table<Role>> GetData(string search, int pageSize, int pageIndex)
        {
            var response = await RoleService.GetModelsByPageAsync(search, pageSize, pageIndex);
            return new Table<Role>(response.Item1, response.Item2);
        }

        [HttpGet]
        [Route("api/Role/GetModel")]
        public Task<Role> GetModel(int id)
        {
            return RoleService.GetByIdAsync(id);
        }

        [HttpGet]
        [Route("api/Role/GetAll")]
        public Task<List<Role>> GetAll()
        {
            return RoleService.GetAll();
        }

        [HttpPost]
        [Route("api/Role/Save")]
        public Task<bool> Save(Role model)
        {
            return RoleService.Save(model);
        }

        [Route("api/Role/Remove")]
        public Task<bool> Remove(int id)
        {
            return RoleService.Remove(id);
        }
    }
}